﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BuildingManager.aspx.cs"
    Inherits="GU.WebERPApp.Aspx.Building.BuildingManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>办公楼管理</title>
    <script src="/Scripts/mini.boot.js" type="text/javascript"></script>
    <style type="text/css">
        .mini-grid-emptyText
        {
            text-align: center;
        }
        .mini-grid-row
        {
            height: 28px;
        }
        form, html, body
        {
            width: 100%;
            height: 100%;
            border: 0;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="mini-toolbar" style="width: 1000px;">
        城市:
        <input id="city" name="City" class="mini-combobox" width="120" valuefield="BId" textfield="City"
            url="/methods/?method=itm.sys.building.getcitylist" required="false" onvaluechanged="cityChange" />&nbsp;&nbsp;
        区:
        <input id="district" name="District" class="mini-combobox" width="150" valuefield="BId"
            textfield="District" required="false" />&nbsp;&nbsp; 办公楼名称:
        <input class="mini-textbox" style="width: 120px" id="buildingName" onenter="search" />&nbsp;&nbsp;
        <a id="btnSearch" class="mini-button" iconcls="icon-search" onclick="search">搜索</a>
        <span class="separator"></span><a id="A2" class="mini-button" iconcls="icon-add"
            onclick="addBuilding">添加办公楼</a> <span class="separator"></span>
    </div>
    <div class="mini-fit" style="width: 1008px; height: 100%">
        <!--该商品相关订单列表-->
        <div id="List" class="mini-datagrid" allowalternating="false" style="width: 100%;
            height: 100%" idfield="orderid" pagesize="20" showfooter="true" showemptytext="true"
            emptytext="未查询到数据" sortmode="server" autohiderowdetail="true">
            <div property="columns">
                <div type="indexcolumn" width="35px">
                </div>
                <div field="City" width="40px" align="center" headeralign="center" allowsort="false">
                    城市</div>
                <div field="District" width="40px" align="center" headeralign="center" allowsort="false">
                    区</div>
                <div field="PinYin" width="30px" align="center" headeralign="center" allowsort="false">
                    拼音</div>
                <div field="BuildingName" width="120px" align="left" headeralign="center" allowsort="false">
                    办公楼名称</div>
                <div field="Address" width="170px" align="left" headeralign="center" allowsort="false">
                    地址</div>
                <div align="center" width="50px" headeralign="center" allowsort="true" renderer="onActionOperate">
                    操作</div>
            </div>
        </div>
        <!--添加办公楼-->
        <div id="winBuild" class="mini-window" title="添加办公楼" style="width: 500px; display: none;"
            showmaxbutton="false" showtoolbar="false" showfooter="false" showmodal="true"
            allowresize="false" allowdrag="true">
            <table style="line-height: 40px; padding: 15px;">
                <tr>
                    <td>
                        办公楼名称：
                    </td>
                    <td>
                        <input name="BId" id="winBuildBId" class="mini-hidden" /><!--隐藏BId-->
                        <input id="bBuildingName" name="BuildingName" class="mini-textbox" width="150" required="true" />
                    </td>
                    <td>
                        拼音
                    </td>
                    <td>
                        <input id="PinYin" name="PinYin" class="mini-textbox" width="150" required="false" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 80px;">
                        城市：
                    </td>
                    <td style="width: 150px;">
                        <input id="bCity" name="City" class="mini-combobox" width="150" valuefield="City"
                            textfield="City" url="/methods/?method=itm.sys.building.getcitylist" required="true"
                            onvaluechanged="bCityChange" />
                    </td>
                    <td style="width: 40px;">
                        区：
                    </td>
                    <td style="width: 150px;">
                        <input name="District" id="tDistrict" class="mini-hidden" /><!--隐藏District-->
                        <input id="bDistrict" name="ParentId" class="mini-combobox" width="150" valuefield="BId"
                            textfield="District" required="true" onvaluechanged="bDistrictChange" />
                    </td>
                </tr>
                <tr>
                    <td>
                        地址：
                    </td>
                    <td colspan="3">
                        <input id="bAddress" name="Address" class="mini-textbox" width="150" required="false" />
                    </td>
                </tr>
                <tr>
                    <td>
                        商业圈：
                    </td>
                    <td colspan="3">
                        <input id="bBusinessArea" name="BusinessArea" class="mini-textbox" width="150" required="false" />
                    </td>
                </tr>
            </table>
            <div style="text-align: center; padding: 10px;">
                <a class="mini-button" onclick="onBuildOk" style="width: 60px; margin-right: 20px;">
                    确定</a> <a class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
            </div>
        </div>
        <!--添加办公楼-->
    </div>
    </form>
</body>
<script type="text/javascript">

    //验证是否存在重复的办公楼
    function ReqBuilding() {
        var buildingName = mini.get("bBuildingName").getValue();
        var city = mini.get("bCity").getValue();
        var district = mini.get("bDistrict").getText();

        return ygopAjaxClient.sync("gu.building.exists", "post", { "buildingName": buildingName, "city": city, "district": district });
    }

    function search() {
        var city = mini.get("city").getText();
        var district = mini.get("district").getText();
        var name = mini.get("buildingName").value;

        mini.get("List").set({ url: "/methods/?method=itm.sys.building.getlist" });
        mini.get("List").load({ "cityName": encodeURIComponent(city), "district": encodeURIComponent(district), "buildingName": encodeURIComponent(name) });

        var act = document.activeElement.tagName.toLowerCase();
        if (act.indexOf("form") != -1) {
            return false;
        }
    }

    function onActionOperate(e) {
        var row = e.record;
        var html = "<a href='javascript:void(0)' onclick=\"editBuilding('" + row.BId + "')\">修改</a>";
        html += "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' onclick=\"deleteBuilding('" + row.BId + "')\">删除</a>";
        return html;
    }

    //修改，打开编辑窗口
    function editBuilding(BId) {
        mini.get("winBuild").show(); //显示弹出层
        var form = new mini.Form("#winBuild");
        form.clear(); //清空form

        ygopAjaxClient.async("gu.building.get", "post", { "BId": BId }, function (e) {
            var json = e[0];
            mini.get("bDistrict").set({ url: "/methods/?method=itm.sys.building.getdistrictlist&CityName=" + json.City }); //加载区列表

            form.setData(json);
        });
    }

    //删除 
    function deleteBuilding(BId) {
        mini.confirm("确定要删除该办公楼吗？", "提示", function (d) {
            if (d == "ok") {
                ygopAjaxClient.async("gu.building.delete", "post", { "BId": BId }, function (e) {
                    if (e.RspCode == 1) {
                        mini.alert("删除成功！");
                        mini.get("List").reload();
                    }
                    else {
                        mini.alert(e.RspMsg);
                    }
                });
            }
        });
    }

    //弹出窗口的城市切换
    function bCityChange() {
        mini.get("bDistrict").setValue(""); //清空区
        var value = mini.get("bCity").getText();
        var cityUrl = "/methods/?method=itm.sys.building.getdistrictlist&CityName=" + encodeURIComponent(value);

        mini.get("bDistrict").load(cityUrl);
    }

    //弹出窗口 区切换
    function bDistrictChange() {
        var district = mini.get("bDistrict").getText();
        mini.get("tDistrict").setValue(district);
    }

    //菜单栏上的城市切换
    function cityChange() {
        var value = mini.get("city").getText();
        var cityUrl = "/methods/?method=itm.sys.building.getdistrictlist&CityName=" + encodeURIComponent(value);

        mini.get("district").load(cityUrl);
    }

    //添加办公楼
    function addBuilding() {
        mini.get("winBuildBId").setValue("InsertBuilding");
        mini.get("winBuild").show(); //显示弹出层
        var form = new mini.Form("#winBuild");
        form.clear(); //清空form
    }

    //编辑修改办公楼
    function onBuildOk() {
        //提交表单数据
        var form = new mini.Form("#winBuild");
        form.validate();
        if (form.isValid() == false) { return; }

        var data = form.getData();      //获取表单多个控件的数据
        var json = mini.encode(data);   //序列化成JSON

        var winBuildBId = mini.get("winBuildBId").value;
        var type = "InsertBuilding";
        if (winBuildBId == "" || !winBuildBId) {
            type = "InsertBuilding";
            var add = ReqBuilding();  //添加模式下，验证是否存在重复办公楼
            if (add) {
                mini.alert("已存在重复的办公楼名称！");
                return;
            }
        }
        else {
            type = "EditBuilding";
        }

        ygopAjaxClient.async("gu.building.add_update", "post", { "submitData": json, "type": type }, function (e) {
            if (e.RspCode == 1) {
                mini.alert(e.RspMsg);
                onCancel();
                mini.get("List").reload();
            }
            else {
                mini.alert(e.RspMsg);
            }
        });
    }

    //取消
    function onCancel() {
        mini.get("winBuild").hide(); //隐藏弹出层
    }
</script>
</html>
